import numpy as np
import cv2

# gg_bond = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\kc.jpg")
# logo = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\logo1.jpg")
# img_logo = cv2.resize(logo, (int(logo.shape[1]), int(logo.shape[0])))
#
# rows, cols, channels = img_logo.shape
# roi = gg_bond[0:rows, 0:cols]
#
# img2gray = cv2.cvtColor(img_logo, cv2.COLOR_BGR2GRAY)
# ret, mask = cv2.threshold(img2gray, 20, 255, cv2.THRESH_BINARY_INV)#得到的mask,logo位置为黑色，其余位置为白色
# mask_inv = cv2.bitwise_not(mask) #  将logo位置变为白色，其余变为黑色
# cv2.imshow('mask_inv' ,mask_inv )
#
# # 将ROI掩码区域黑化
# img_base_bg = cv2.bitwise_and(roi, roi, mask = mask)
# img_logo_fg = cv2.bitwise_and(img_logo, img_logo, mask = mask_inv)#得到彩色logo区域，其余位置为黑色
#
# dst = cv2.add(img_base_bg, img_logo_fg)
# gg_bond[0:rows, 0:cols] = dst
#
#
# cv2.imshow('img_base_bg', img_base_bg)
# cv2.imshow('img_logo_fg', img_logo_fg)
# cv2.imshow('res', gg_bond)
# cv2.imshow('mask_inv', mask_inv)
#
# cv2.imshow('dst', dst)
#
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#
# cv2.imwrite('result.png', gg_bond)


gg_bond = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\kc.jpg")
logo = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\logo1.jpg")
print(gg_bond.shape)
rows, cols, channels = logo.shape
mask = np.zeros((rows, cols), np.uint8)
# 取反
mask[::] = 255
m = cv2.bitwise_not(mask)
roi = gg_bond[0:rows, 0:cols]
tem = cv2.bitwise_and(roi, roi, mask=m)
dst = cv2.add(tem, logo)
gg_bond[0:rows, 0:cols] = dst
cv2.imshow("gg_bond", gg_bond)
cv2.imshow("dst", dst)
cv2.imshow('tem', tem)
cv2.imshow('mask', mask)
cv2.waitKey(0)

